Data Structure - Interview Questions and Answers for 'Data structure' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers - Order By Rating

   next 30
 Q31. Write a Program to implement stack using LinkedList.Data Structure
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Data Structure


 Q32. What is the access time for ArrayList and LinkedList ?Data Structure
Ans. O(1) for ArrayList
O(n) for LinkedList

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve          Asked in 2 Companies


 Q33. What is the "multiplicative congruence" method for determining where an element belongs in a hash table ?Data Structure
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q34. Describe how a queue is usually created using sequential allocation.Data Structure
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q35. If a stack is implemented using linkedlist, which end (head or tail) should represent the top ?Data Structure
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q36. If a stack is implemented using an array, which end (head or tail) should represent the top ?Data Structure
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q37. Can we access elements at a particular index using LinkedList collection class ?Data Structure
Ans. Yes we can. But as the underlying structure of the collection class is double linked list, it will eventually have to traverse to the element linearlly and hence would result in bad performance.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q38. Which of the following - arrays or LinkedList allow elements to be accessed using index and how ? Data Structure
Ans. Arrays allows elements to be accessed directly using the index.

As Array elements are stored in continuous memory locations it's very easy to find the memory address of any element using the formula as following

Memory Address of Array start or index 0 + ( Size of array element * Index )

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays  linkedlist


 Q39. Difference between Arrays and LinkedList ?Data Structure
 This question was recently asked at 'Spillman Technologies,Motorola Solutions'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve          Asked in 2 Companies


 Q40. How are hash codes generated ?Data Structure
Ans. Use hashCode() which returns an integer value, generated by a hashing algorithm

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hash codes  hashcode     Asked in 1 Companies


 Q41. Create a stack of specific size using arrayList?Data Structure
Ans. public class StackUsingArrayList {
   public static void main(String[] args) {
      List list = new ArrayList();
      list.add("A");
      list.add("B");
      list.add("C");
      
      Stack stack = new Stack();

      list.forEach(a -> stack.add(a));
      System.out.println(stack);
   
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve          Asked in 1 Companies


 Q42. How would you implement low latency data structures ?Data Structure
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q43. Find Max from Stack in O(1) complexityAlgorithm
Ans. Create one extra field called MAX O(1)

when you an element to the stack check these two condition
1. Stack is empty, then MAX = element
2. Stack is not empty then check if the element is greater than MAX then MAX = element


when getMax fuction is called, then return MAX

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     complexity  stack  data structure     Asked in 1 Companies


 Q44. What are the ways to get the values from list ?Data Structure
Ans. list.get(index);

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     list     Asked in 1 Companies


 Q45. Explain what happens when insertion is performed in case of ArrayList and LinkedList.Data Structure
Ans. Array List works on Array and when we add an element in middle of the list, Array List need to update the index of all subsequent elements. I the capacity is full, it even may need to move the whole list to a new memory location . Linked List works on Double linked list algorithm and all it has to do is to adjust the address of the previous and next elements.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arraylist vs linkedlist  collections  list     Asked in 2 Companies


 Q46. Write an efficient program for printing k largest elements in an array. Elements in array can be in any order.Data Structure
 This question was recently asked at 'Amazon'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays  coding  code     Asked in 1 Companies


 Q47. Write a program for binary tree ?Data Structure
Ans. public class BinarySearchTree {
//Represent the node of binary tree
public static class Node {
int data;
Node left;
Node right;
public Node(int data) {
//Assign data to the new node, set left and right children to null

this.data = data;
this.left = null;
this.right = null;
}
}
//Represent the root of binary tree

public Node root;
public BinarySearchTree() {
root = null;
}

//factorial() will calculate the factorial of given number

public int factorial(int num) {
int fact = 1;
if (num == 0) return 1;
else {
while (num > 1) {
fact = fact * num;
num--;
}
return fact;
}
}

//numOfBST() will calculate the total number of possible BST by calculating Catalan Number for given key

public int numOfBST(int key) {
int catalanNumber = factorial(2 * key) / (factorial(key 1) * factorial(key));
return catalanNumber;
}
public static void main(String[] args) {
BinarySearchTree bt = new BinarySearchTree();

//Display total number of possible binary search tree with key 5

System.out.println("Total number of possible Binary Search Trees with given key: "
bt.numOfBST(5));
}
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve          Asked in 1 Companies


 Q48. Which of the two - Arrays or LinkedList - is a better data structure for implementing Queue ? and Why ?Data Structure
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Arraylist  linkedlist  queue  collections


 Q49. Which Data structure can be used for creating Queue ?Data Structure
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     queue  collections  data structure


 Q50. In a Tree, find common ancestor of two nodes.Data Structures
 This question was recently asked at 'Amazon'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Tree  Data structures     Asked in 1 Companies


 Q51. Write method to delete Node from a LinkedList.Data Structure
Ans. public class LinkedList {

   Node start = null;
   Node head = null;

   class Node {
      Integer body;
      Node nextNode;

      Node(Integer value) {
         body = value;
      }
   }

   private void addNodeToEnd(Integer value) {
      if (start == null) {
         start = new Node(value);
         head = start;
         head.nextNode = null;
         return;
      }

      while (head.nextNode != null) {
         head = head.nextNode;
      }

      head.nextNode = new Node(value);
   }
   
   private void deleteNode(Integer value) {
      head = start;
      while (head.nextNode != null) {
         if(head.nextNode.body == value){
            head.nextNode = head.nextNode.nextNode;
         }
         
         head = head.nextNode;
      }
   }
   
   

   private void traverse() {
      head = start;
      while (head != null) {
         System.out.println(head.body);
         head = head.nextNode;
      }
   }

   public static void main(String[] args) {
      LinkedList ll = new LinkedList();

      ll.addNodeToEnd(5);
      ll.addNodeToEnd(10);
      ll.addNodeToEnd(15);

      ll.traverse();
      
      ll.deleteNode(10);
      
      ll.traverse();

   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     linkedlist  delete node from linkedlist


 Q52. In a Linked list with sorted numbers, insert a new numbers while maintaining the sort order.Algorithm
Ans.
public class LinkedList {

   Node start = null;
   Node head = null;
   
   class Node{
      Integer body;
      Node nextNode;
      
      Node(Integer value){
         body = value;
      }
   }
   
   private void insertInMiddle(Integer value){
      head = start;
      if(start == null) {
         start = new Node(value);
         head = start;
         head.nextNode = null;
         return;
      }
      
      while(head.body < value){
         if(head.nextNode == null || head.nextNode.body >= value){
            Node newNode = new Node(value);
            newNode.nextNode = head.nextNode;
            head.nextNode = newNode;
            
            break;
         }   
         head = head.nextNode;
      }
   }
   
   private void traverse(){
      head = start;
      while(head != null){
         System.out.println(head.body);
         head = head.nextNode;
      }
   }
   
   public static void main(String[] args){
      LinkedList ll = new LinkedList();
      
      ll.insertInMiddle(5);
      ll.insertInMiddle(10);
      ll.insertInMiddle(15);
      ll.insertInMiddle(7);
      
      ll.traverse();
      
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     LinkedList  Data structures  Algorithm


 Q53. Write a program for LinkedList, with method to append node and traversing the list ?Algorithm
Ans. public class LinkedList {

   Node start = null;
   Node head = null;

   class Node {
      Integer body;
      Node nextNode;

      Node(Integer value) {
         body = value;
      }
   }

   private void addNodeToEnd(Integer value) {
      if (start == null) {
         start = new Node(value);
         head = start;
         head.nextNode = null;
         return;
      }

      while (head.nextNode != null) {
         head = head.nextNode;
      }

      head.nextNode = new Node(value);
   }

   private void traverse() {
      head = start;
      while (head != null) {
         System.out.println(head.body);
         head = head.nextNode;
      }
   }

   public static void main(String[] args) {
      LinkedList ll = new LinkedList();

      ll.addNodeToEnd(5);
      ll.addNodeToEnd(10);
      ll.addNodeToEnd(15);

      ll.traverse();

   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     LinkedList  Data structures  Algorithm


 Q54. Difference between Tree and Graph ?Data Structures
Ans. Graph contain cycles whereas Trees cannot.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     graph  trees  data structures  tree vs graph


 Q55. What is the difference between Stack and Queue ?Data Structures
Ans. Stack is based on Last in First out (LIFO) principle while a queue is based on FIFO (First In First Out) principle.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     data structure  stack vs queue  stack  queue      Basic


 Q56. Write a Program to delete a node from Linked List ?Data Structure
 This question was recently asked at 'Caprus IT'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     linkedlist  delete a node from linked list     Asked in 1 Companies


 Q57. How to implement a hashtable ?Data Structure
 This question was recently asked at 'MarkMonitor'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hashtable     Asked in 1 Companies


 Q58. Implement stack using generics in Java.Data Structure
 This question was recently asked at 'Bind Software Innovations'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     oding  cod     Asked in 1 Companies


 Q59. Find the third last element in a linked list ?Data Structure
Ans. First Find the number of nodes in the linked list and take it as n.then find the data at n-3 element.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     linkedlist     Asked in 1 Companies


 Q60. Write a Program to merge two sorted arrays ?Data Structure
Ans. We can merge two sorted array by using quick sort algorithm

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays  merge sorted arrays     Asked in 2 Companies


previous 30   next 30

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: